package com.lqian.demo02.part5.dao;

import com.lqian.demo02.part5.common.BaseDao;
import com.lqian.demo02.part5.common.BaseDao2;
import com.lqian.demo02.part5.pojo.User;
import com.lqian.demo02.part5.utils.JdbcUtils2;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;
import java.util.List;

/**
 * 数据库连接对象不再需要service层传递过来，
 * 而是直接从JdbcUtils2提供的getConnection方法去获取
 * @author：Melody_LQ
 * @time：2022/7/14 6:14 下午
 */
public class UserDaoImpl2 extends BaseDao2<User> implements UserDao{

    //QueryRunner queryRunner = new QueryRunner();
    // public <T> T query(Connection conn, String sql, ResultSetHandler<T> rsh)

    @Override
    public int addUser(User user) throws SQLException {
        String sql = "insert into users(name,password,email,birthday) values(?,?,?,?)";
        Object[] params = {user.getName(),user.getPassword(),
                user.getEmail(),user.getBirthday()};
        return execute(sql,params);
    }

    @Override
    public int updateUser(User user, int id) {

        return 0;
    }

    @Override
    public int delUserById(int id) {
        return 0;
    }

    @Override
    public User selectUserById(int id) {
        return null;
    }

    @Override
    public List<User> selectAllUsers() {
        return null;
    }
}
